"""
图标加载工具
"""
import os
import sys
from PyQt6.QtGui import QIcon


def get_icon_path():
    """获取icon.ico文件路径"""
    # 首先尝试从程序所在目录加载
    if hasattr(sys, '_MEIPASS'):
        # PyInstaller打包后的路径
        icon_path = os.path.join(sys._MEIPASS, 'icon.ico')
    else:
        # 开发环境下的路径
        current_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
        icon_path = os.path.join(current_dir, 'icon.ico')
    
    return icon_path if os.path.exists(icon_path) else None


def load_app_icon():
    """加载应用图标"""
    icon_path = get_icon_path()
    if icon_path:
        return QIcon(icon_path)
    return QIcon()  # 返回空图标

